<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${namespace}">
    <!-- Result Map-->
    <resultMap id="${entityName}" type="${entityType}">
${resultMap}
    </resultMap>

    <!-- 所有列 -->
    <sql id="allColumn">
        ${allColumn}
    </sql>

    <!-- 批量新增 -->
    <insert id="batchAdd" parameterType="Object" >
        insert into ${tableName}
        (${addProperty})
        values
        <foreach collection="entityList" index="index" item="item" separator=",">
            (${batchAddValue})
        </foreach>
    </insert>

    <!-- 批量更新 -->
    <update id="batchUpdate" parameterType="Object">
        <foreach collection="entityList" separator=";" item="item">
            update ${tableName} set
            <trim  suffixOverrides="," >
${updateBatchColProps}
            </trim>
            where member_id = <#noparse>#{memberInfo.memberId}</#noparse>
            and member_no = <#noparse>#{memberInfo.memberName}</#noparse>
            and id = <#noparse>#{item.id}</#noparse>
        </foreach>
    </update>

     <!-- 批量删除 -->
    <delete id="batchDelete" parameterType="Object">
        delete from ${tableName}
        where member_id = <#noparse>#{memberInfo.memberId}</#noparse>
        and member_no = <#noparse>#{memberInfo.memberName}</#noparse>
        and id in
        <foreach collection="ids" item="item" open="(" separator="," close=")">
            <#noparse>#{item}</#noparse>
        </foreach>
    </delete>

    <!-- 批量逻辑删除 -->
    <delete id="batchLogicDelete" parameterType="Object">
        update ${tableName} set is_deleted = 1
        where member_id = <#noparse>#{memberInfo.memberId}</#noparse>
        and member_no = <#noparse>#{memberInfo.memberName}</#noparse>
        and id in
        <foreach collection="ids" item="item" open="(" separator="," close=")">
            <#noparse>#{item}</#noparse>
        </foreach>
    </delete>

    <!-- 批量查询 -->
    <select id="list" resultMap="${entityName}">
        select
        <include refid="allColumn" />
        from ${tableName}
        where member_id = <#noparse>#{memberInfo.memberId}</#noparse>
        and member_no = <#noparse>#{memberInfo.memberName}</#noparse>
        and is_deleted = 0
        and id in
        <foreach collection="ids" item="item" open="(" separator="," close=")">
            <#noparse>#{item}</#noparse>
        </foreach>
    </select>

    <!-- 批量条件查询 -->
    <select id="listByFilter" resultMap="${entityName}">
        select
        <include refid="allColumn" />
        from ${tableName}
        where member_id = <#noparse>#{memberInfo.memberId}</#noparse>
        and member_no = <#noparse>#{memberInfo.memberName}</#noparse>
        and is_deleted = 0
        <include refid="mainFilter"/>
    </select>

    <!-- 主页面过滤条件 -->
    <sql id="mainFilter">
${findListCondition}
    </sql>

    <!-- 主页面查询 -->
    <select id="listMain" resultMap="${entityName}">
        select
        <include refid="allColumn" />
        from ${tableName}
        where member_id = <#noparse>#{memberInfo.memberId}</#noparse>
        and member_no = <#noparse>#{memberInfo.memberName}</#noparse>
        and is_deleted = 0
        <include refid="mainFilter"/>
        limit <#noparse>#{pageInfo.offset},#{pageInfo.pageSize}</#noparse>
    </select>

    <!-- 主页面查询count -->
    <select id="listCount" resultType="Integer">
        select
        count(*)
        from ${tableName}
        where member_id = <#noparse>#{memberInfo.memberId}</#noparse>
        and member_no = <#noparse>#{memberInfo.memberName}</#noparse>
        and is_deleted = 0
        <include refid="mainFilter"/>
    </select>

    <!-- 获取最大的no -->
    <select id="getMaxNo" resultType="Integer">
        select
        max(no)
        from ${tableName}
        where member_id = <#noparse>#{memberInfo.memberId}</#noparse>
        and member_no = <#noparse>#{memberInfo.memberName}</#noparse>
    </select>

</mapper>